<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        const str = "Js高阶函数JS"
        const key = "js"
        function heighLigt(str, key) {
            // ....
            const reg = new RegExp(key, 'ig')
            console.dir(reg)
            const newStr = str.replace(reg, function(p) {
                console.log('匹配到的内容是', p)
                return "<span>"+p+"</span>"
            })

            return newStr
        }

        const newStr = heighLigt(str, key) // <span>Js</span>高阶函数<span>JS</span>
        console.log(newStr)
    </script>
</body>
</html>